<?php
$startMemory = memory_get_usage();
session_start();

$mtime = microtime();
$mtime = explode(' ', $mtime);
$mtime = $mtime[1] + $mtime[0];
$starttime = $mtime;

$basePath = substr($_SERVER['SCRIPT_NAME'], 0, strrpos($_SERVER['SCRIPT_NAME'], "/")+1);

include_once 'php/includes.php';
$logger->info('Start=======================================index page=======================================Start');
$logger->info('Memory Usage: ' . memory_get_usage());


if(!isset($_SESSION['skin'])){
	$_SESSION['skin'] = $config['skin'];
}

$_SESSION['resolution'] = $browser->Resolution['display'];

switch ($browser->Device) {
    case 'Popcorn Hour C-200' || 'PC':
        $homePath = $basePath . 'devices/pch_c200/skins/' . $_SESSION['skin'];
        $_SESSION['homePath'] = $homePath;
        include 'devices/pch_c200/skins/' . $_SESSION['skin'] . '/main.php';
        break;
    case 'Popcorn Hour A-110':
        $homePath = $basePath . 'devices/pch_a110/skins/' . $_SESSION['skin'];
        $_SESSION['homePath'] = $homePath;
        include 'devices/pch_a110/skins/' . $_SESSION['skin'] . '/main.php';
        break;
    case 'PC':
        $homePath = $basePath . 'devices/pc/skins/' . $_SESSION['skin'];
        $_SESSION['homePath'] = $homePath;
        include 'devices/pc/skins/' . $_SESSION['skin'] . '/main.php';
        break;
    default:
        echo '<h1>Wrong Way Go Back</h1>';
        echo '<h1>Unknown devices ' . $NMTBrowser->Device . ' please add to the switch list in index.php</h1>';
        echo '<h1>And add skin :)</h1>';
        $logger->debug('$browser: ' . $browser->DisplayInfo());
        break;
}

$logger->info('Memory Usage: ' . memory_get_usage());
$logger->info('Peak Memory Usage: ' . memory_get_peak_usage());
$mtime = microtime();
$mtime = explode(" ", $mtime);
$mtime = $mtime[1] + $mtime[0];
$endtime = $mtime;
$totaltime = ($endtime - $starttime);
$logger->debug('Defined Variables:');
$logger->debug(array_keys(get_defined_vars()));
$logger->info('Code Monkeys Took ' .$totaltime. ' seconds while using ' . (memory_get_peak_usage() / 1024 / 1024) . ' Megabytes');

unset($totaltime);
unset($mtime);
unset($endtime);

$logger->info('Memory Usage: ' . memory_get_usage());
$logger->info('Memory Left over: ' . (memory_get_usage() - $startMemory));
$logger->info('End=======================================index page=======================================End');
?>